package com.taurus.isms;


import com.taurus.util.HanziToPinyin;
import com.taurus.util.HanziToPinyin.Token;
import com.taurus.wiget.ScaleImageView;

import android.R.color;
import android.animation.Animator;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.FilterQueryProvider;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListPopupWindow;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.SimpleCursorAdapter.ViewBinder;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import android.net.Uri;
public class TestActivity extends Activity {


	ViewPager mMmsViewPager;
	MmsMediaPagerAdapter mMmsMediaPagerAdapter ;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_test);

		//tv = (TextView) findViewById(R.id.testText);
		List <String> list = new ArrayList<String>();
		list.add("/storage/emulated/0/netease/auto/netease_temp_pic/auto2011726201107261030119bf87.jpg");
		list.add("/storage/emulated/0/netease/auto/netease_temp_pic/auto2013326201303262323448922e.jpg");
		
		
		
		mMmsViewPager = (ViewPager) findViewById(R.id.mmsViewPager);
		mMmsMediaPagerAdapter = new MmsMediaPagerAdapter(this.getApplicationContext());
		mMmsMediaPagerAdapter.change(list);
		mMmsViewPager.setAdapter(mMmsMediaPagerAdapter);
		mMmsViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				
				ScaleImageView preView =(ScaleImageView) mMmsMediaPagerAdapter.getPreView();
				if(preView != null){
					preView.resetImage();
				}else{
					ScaleImageView iv = (ScaleImageView)mMmsViewPager.getChildAt(0);
					iv.resetImage();
				}
				
				
				ScaleImageView currentView = (ScaleImageView)mMmsViewPager.getChildAt(arg0);
				mMmsMediaPagerAdapter.setPreView(currentView);
			
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		
		
		
		
	}
	
	
	
	
	class MmsMediaPagerAdapter extends PagerAdapter{

		private View preView;
		private View currentView;
		
		public void setPreView(View view){
			preView = view;
		}
		public View getPreView(){
			return preView;
		}
		public void setCurrentView(View view){
			currentView = view;
		}
		
		public View getCurrentView(){
			return currentView;
		}
		
		private List<String> mPaths;
		private Context mContext;
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mPaths.size();
		}

		public MmsMediaPagerAdapter(Context context){
			mContext = context;
		}
		
		
		public void change(List<String> paths){
			mPaths = paths;
		}
		
		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			
			
			return arg0 ==(View)arg1;
		}

		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			// TODO Auto-generated method stub
			ScaleImageView iv = new ScaleImageView(mContext);
			iv.setScaleType(ScaleType.MATRIX);
			try{
				Bitmap bm = BitmapFactory.decodeFile(mPaths.get(position)); 
				iv.setImageBitmap(bm);
			}catch(Exception e){
				e.printStackTrace();
			}
			((ViewPager)container).addView(iv, 0);
			return iv;
			
			
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			// TODO Auto-generated method stub
			//super.destroyItem(container, position, object);
			container.removeView((View)object);
		}
		
		
		
		
		
	 
		
	}
  

}
